package top.huanyv.tools.bean;

public class Progress {

    private static final int LEN = 50;

    /**
     * 总量
     */
    private long total;

    /**
     * 进度百分比
     */
    private long progress;


    public Progress(long total) {
        this.total = total;
    }

    public void update(long curTotal) {
        // 计算进度
        this.progress = (long) Math.floor(((double) curTotal / total) * 100);
    }


    public void print() {
        int len = (int) (this.progress / 2);
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (int i = 0; i < 50; i++) {
            if (i < len) {
                sb.append("=");
            } else {
                sb.append(" ");
            }
        }
        sb.append("]");
        sb.append(progress).append("%");

        System.out.print(sb.toString());
        System.out.print("\r");
    }


}